﻿using UnityEngine;
using System.Collections;

[AddComponentMenu("TagMachine/UI/Menu/Launcher")]
public class UIGameModeLauncher : MonoBehaviour
{
	public string AllModesLevelName 	= "AllModes";

	private GameObject m_PrefabMode 	= null;

	public void QuitApp()
	{
		Application.Quit ();
	}

	public void SaveMode( GameObject _PrefabMode )
	{
		m_PrefabMode 		= _PrefabMode;
	}

	public void LaunchMode()
	{
		Application.LoadLevel( AllModesLevelName );
	}

	void Awake()
	{
		DontDestroyOnLoad( this );
	}

    void OnLevelWasLoaded( int _Level )
    {
        if ( _Level > 0 )
        {
        	Instantiate( m_PrefabMode );

			// TODO
			// This avoid goind back to main menu with already existing Launcher
			// The new launcher needs to stay for button events
			// The existing one isn't needed anymore, it can be destroyed
			Destroy( gameObject );
        }
    }
}
